package com.lq.ecoldchain.ui.mine.user.phonenew

import android.arch.lifecycle.MutableLiveData
import com.lq.ecoldchain.base.viewmodel.BaseViewModel
import com.lq.ecoldchain.internet.BaseObserver
import com.lq.ecoldchain.util.DialogUtils
import com.lq.ecoldchain.util.toast

/*
*2019/1/5 0005  9:42
*function by lq
*/
class PhoneNewViewModel : BaseViewModel() {
    val newPhone by lazy { MutableLiveData<String>() }
    val newCOde by lazy { MutableLiveData<String>() }
    var newToken = ""


    fun sendNewCode() {
        if (newPhone.value.isNullOrEmpty()) {
            toast { "请填写手机号码" }
        } else {
            BaseNetCore.ApiServiceImpl.sendUpdatePhoneOldCode(newPhone.value!!).compose(RxTransformer.switchSchedulers()).subscribe(object : BaseObserver<String>() {
                override fun onSuccess(t: String?) {
                    toast { "发送成功" }
                }

                override fun onFail(code: String) {
                    toast { "发送失败" }
                }
            })
        }
    }

    fun commitNew() {
        if (newPhone.value.isNullOrEmpty() || newCOde.value.isNullOrEmpty()) {
            toast { "请填写好数据" }
        } else {
            if (newToken.isEmpty()) {
                toast { "修改手机数据传输错误" }
            }else
            BaseNetCore.ApiServiceImpl.bindPhoneNew(newToken, newPhone.value!!, newCOde.value!!).compose(RxTransformer.switchSchedulers()).subscribe(object : BaseObserver<String>() {
                override fun onSuccess(t: String?) {
                    toast { "修改手机号码成功" }
                }

                override fun onFail(code: String) {

                }
            })
        }
    }
}